package ace.module.sms.core.impl.dao.aggregate.impl;

import ace.module.sms.core.impl.dao.aggregate.SmsApplicationAggregate;
import ace.module.sms.core.impl.dao.entity.SmsApplication;
import ace.module.sms.core.impl.dao.entity.SmsApplicationConfig;
import ace.module.sms.core.impl.dao.entity.SmsSupplier;
import ace.module.sms.core.impl.dao.repository.SmsApplicationConfigRepository;
import ace.module.sms.core.impl.dao.repository.SmsApplicationRepository;
import ace.module.sms.core.impl.dao.repository.SmsSupplierRepository;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * 短信应用 aggregate implement.
 *
 * @author Caspar
 */
@Slf4j
@AllArgsConstructor
@Component
public class SmsApplicationAggregateImpl implements SmsApplicationAggregate {
  private final SmsApplicationRepository smsApplicationRepository;
  private final SmsApplicationConfigRepository smsApplicationConfigRepository;
  private final SmsSupplierRepository smsSupplierRepository;

  @Transactional(rollbackFor = Exception.class)
  @Override
  public void insert(
      SmsApplication smsApplication,
      SmsApplicationConfig smsApplicationConfig,
      SmsSupplier smsSupplier) {
    this.smsApplicationRepository.insert(smsApplication);
    this.smsApplicationConfigRepository.insert(smsApplicationConfig);
    this.smsSupplierRepository.insert(smsSupplier);
  }
}
